#ifndef AUDIODATA_H
#define AUDIODATA_H

#include <QObject>
#include <QAudioDecoder>
#include <QAudioBuffer>
#include <QDebug>
#include <QAudioDecoderControl>
#include <QFile>
#include "libzplay.h"
#include <QTimer>
using namespace libZPlay;

class AudioData : public QObject
{
    Q_OBJECT
public:
    explicit AudioData(QObject *parent = 0);

    Q_INVOKABLE void setSource(QString source);
    Q_INVOKABLE void playMusic();
    Q_INVOKABLE void stopMusic();
    Q_INVOKABLE void pauseMusic();
    Q_INVOKABLE void seekPosition(int ms);
    Q_PROPERTY(int amplitude READ amplitude NOTIFY amplitudeChanged)
    Q_PROPERTY(int position READ position NOTIFY positionChanged)
    Q_PROPERTY(bool isPlaying READ isPlaying NOTIFY isPlayingChanged)

signals:
    void amplitudeChanged();
    void positionChanged();
    void isPlayingChanged();

public slots:
    void refreshDatas();
private:
    ZPlay *player;
    QTimer timer;
    int  pnHarmonicNumber[512];
    int  pnHarmonicFreq[257];
    int  pnLeftAmplitude[257];
    int  pnRightAmplitude[257];
    int  pnLeftPhase[257];
    int  pnRightPhase[257];
    int mposition=0;
    bool isMusicPlaying;

    int amplitude(){
//        return pnRightAmplitude[150];
        return pnRightAmplitude[171];
    }
    int position(){
        return mposition;
    }
    bool isPlaying(){
        return isMusicPlaying;
    }
};


#endif // AUDIODATA_H
